package com.zhongge.servlet;

import com.zhongge.entity.Student;
import com.zhongge.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @ClassName StudentInfoServlet
 * @Description TODO
 * @Author zhongge
 * @Version 1.0
 */
@WebServlet("/list")
public class StudentInfoServlet extends HttpServlet {
    StudentService studentService = new StudentService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ArrayList<Student> students= studentService.findAll();
        req.setAttribute("students", students);
        //转发
        req.getRequestDispatcher("student/list.jsp").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //注意 a标签他走的是 get请求所以我们使用post的逻辑就得在这里进行调用post的方法
        doPost(req, resp);
    }
}
